//
//  BagRankDetailsViewController.m
//  HongFuShop
//
//  Created by chirui on 2017/8/9.
//  Copyright © 2017年 Shui. All rights reserved.
//

#import "BagRankDetailsViewController.h"
#import "RankActMessageViewController.h"
#import "SalesRankViewController.h"
#import "CompetitionListViewController.h"

@interface BagRankDetailsViewController (){
    
    NSString * urlStr;
}

@property (nonatomic, strong) UIWebView *webView;

@end

@implementation BagRankDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.view.backgroundColor =[UIColor whiteColor];
    
    self.navigationItem.titleView = [TopLabel withLabelWithLabelText:@"活动详情"];
    
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithIcon:@"icon_public_return" target:self action:@selector(back)];
    
    [self creatWebWith:self.dataDic[@"detail"]];
   
    [self creatDownView];
}

// 底部按钮UI
-(void)creatDownView {
    
    UIView * downView =[[UIView alloc]initWithFrame:CGRectMake(0, HEIGHT-48-64, WIDTH, 48)];
    
    downView.backgroundColor = [UIColor whiteColor];
    
    
    UIView * oneView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH/4, 48)];
    [oneView tapAction:^{
        
         NSLog(@"活动权限");
        RankActMessageViewController * rank = [[RankActMessageViewController alloc]init];
        rank.urlStr = self.dataDic[@"permission"];
        rank.titleStr = @"活动权限";
        [self.navigationController pushViewController:rank animated:YES];
        
    }];
    
    UIImageView * callSeller =[[UIImageView alloc]initWithFrame:CGRectMake((WIDTH/4-30)/2, 2, 30, 30)];
    callSeller.image = ImageName(@"icon_details_activity");
    [oneView addSubview:callSeller];
    
    UILabel * sellLabel =[[UILabel alloc]initWithFrame:CGRectMake(0, 33, WIDTH/4, 14)];
    sellLabel.textAlignment = NSTextAlignmentCenter;
    sellLabel.font = [UIFont systemFontOfSize:12];
    sellLabel.textColor = RGB(0x666666);
    sellLabel.text = @"活动权限";
    [oneView addSubview:sellLabel];
    
    [downView addSubview:oneView];
    
    
    UIView * twoView = [[UIView alloc]initWithFrame:CGRectMake(WIDTH/4, 0, WIDTH/4, 48)];
    [twoView tapAction:^{
        
        RankActMessageViewController * rank = [[RankActMessageViewController alloc]init];
        rank.urlStr = self.dataDic[@"award_rules"];
        rank.titleStr = @"奖励规则";
        [self.navigationController pushViewController:rank animated:YES];
        NSLog(@"奖励规则");
    }];
    UIImageView * myComment =[[UIImageView alloc]initWithFrame:CGRectMake((WIDTH/4-30)/2, 2, 30, 30)];
    myComment.image = ImageName(@"icon_details_reward");
    [twoView addSubview:myComment];
    
    UILabel * commentLabel =[[UILabel alloc]initWithFrame:CGRectMake(0, 33, WIDTH/4, 14)];
    commentLabel.textAlignment = NSTextAlignmentCenter;
    commentLabel.font = [UIFont systemFontOfSize:12];
    commentLabel.textColor = RGB(0x666666);
    commentLabel.text = @"奖励规则";
    [twoView addSubview:commentLabel];
    
    [downView addSubview:twoView];
    
    UIView * threeView = [[UIView alloc]initWithFrame:CGRectMake(WIDTH/4*2, 0, WIDTH/4, 48)];
    [threeView tapAction:^{
        
        if ([self.typeStr isEqualToString:@"display"]) { //陈列大奖投票
            
            SalesRankViewController * sales =[[SalesRankViewController alloc]init];
            sales.activity_id = self.dataDic[@"activity_id"];
            [self.navigationController pushViewController:sales animated:YES];
        }else {
        
            CompetitionListViewController * competition =[[CompetitionListViewController alloc]init];
            competition.activity_id = self.dataDic[@"activity_id"];
            [self.navigationController pushViewController:competition animated:YES];
        }
        
        
    }];
    UIImageView * rankImage =[[UIImageView alloc]initWithFrame:CGRectMake((WIDTH/4-30)/2, 2, 30, 30)];
    rankImage.image = ImageName(@"icon_details_ranking");
    [threeView addSubview:rankImage];
    
    UILabel * rankLabel =[[UILabel alloc]initWithFrame:CGRectMake(0, 33, WIDTH/4, 14)];
    rankLabel.textAlignment = NSTextAlignmentCenter;
    rankLabel.font = [UIFont systemFontOfSize:12];
    rankLabel.textColor = RGB(0x666666);
    rankLabel.text = @"查看排名";
    [threeView addSubview:rankLabel];
    
    [downView addSubview:threeView];
    
    
    UIImageView * addImage = [[UIImageView alloc]initWithFrame:CGRectMake(WIDTH/4*3, 0,WIDTH/4, 48)];
    [addImage tapAction:^{
        
        [self activityEntryFor:self.dataDic[@"activity_id"]];
    }];
    addImage.image = ImageName(@"img_home_nav_bg");
    //    addCarImage.userInteractionEnabled = YES;
    [downView addSubview:addImage];

    UILabel * carLabel =[[UILabel alloc]initWithFrame:CGRectMake(0, 0, WIDTH/4, 48)];
    carLabel.textAlignment = NSTextAlignmentCenter;
    carLabel.font = [UIFont systemFontOfSize:15];
    carLabel.textColor = [UIColor whiteColor];
    carLabel.text = @"我要参加";
    [addImage addSubview:carLabel];
    
  
    
    [self.view addSubview:downView];
    
}

-(void)creatWebWith:(NSString *)str {
    
    _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,WIDTH, HEIGHT-64-48)];
    _webView.scalesPageToFit = YES;
    
    NSURL* url =[NSURL URLWithString:str];
    
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [_webView loadRequest:request];
    
    [self.view addSubview:self.webView];
    
}

-(void)back{
    
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)activityEntryFor:(NSString *)entry{
    
    
    NSDictionary * dic = @{@"user_id":USER_DEFAULTGet(@"user_id"),
                           @"token":USER_DEFAULTGet(@"token"),
                           @"activity_id":entry};
    
    SHuiMBhubNoTimeLoding;
    [PostNetWorking postNetWorkingStr:RequestUrlStr(entry_activity_api) andparameters:dic Success:^(id responseObject) {
        SHuiMBHidleYes;
        if (codeSucess) {
            
            SHuiMBhudTextTimeStr(@"参加成功");

        }else {
            
            SHuiMBhudTextTimeStr(responseObject[@"mark"]);
        }
    } failed:^(NSError *error) {
        SHuiMBHidleYes;
        SHuiMBhudTextNetError;
    }];
    
}




@end
